<template>
		
	<view class="equipment">
		<view class="equipment-navbar">
			<!-- #ifdef MP-WEIXIN -->
			<u-navbar placeholder  title="设备" autoBack leftIconColor="#fff"  bgColor="#2a80f7" :titleStyle="{color:'#fff'}" >
			</u-navbar>
			<!-- #endif -->
			<view class="equipment-add">
				<view class="">
					<u-tabs :list="list1" @click="handleTabs" :inactiveStyle="{
				    color: '#fff',
				    transform: 'scale(1)'
				}" lineColor="#F99E35"
				:activeStyle="{
				    color: '#fff',
				    fontWeight: 'bold',
				    transform: 'scale(1.05)'
				}"></u-tabs>
						</view>
						<view class="right" v-if="!activeTab" >
							<view class="add-btn" @tap="isAdd=!isAdd">
								添加设备 [+] 
							</view> 
							
							</view>
						
						<view class="right" v-else @tap="handleDial">拨号设置</view>
			</view>
		</view>
		<scroll-view scroll-y="true" v-if="!activeTab">
			<view class="equipment-main">
				<view class="mask" v-show="isAdd" @tap="isAdd=false">
					<view class="position-add">
						<view class="item-add" @tap="handleScanCode">
							扫码绑定
						</view>
						<view class="item-add" @tap="handleAdd">
							添加设备
						</view>
					</view>
				</view>
				<view class="top_equipment">
					<view :class="activeIndex==index?'top_item active':'top_item'" v-for="(item,index) in  equipment"
						:key="index" @click="clickItem(item,index)">
						<view class="title">
							{{item.title}}
						</view>
					</view>
				</view>
				<view class="top_box">
					<view class="l" @click="changeActiveName('GroupList')">
						<text>{{activeName}}({{count}}台)</text>
						<!-- <image src="/static/newProject/equipment/equipment1.png" mode=""></image> -->
					</view>
					<view class="r">
						<image style="width: 24rpx;height: 24rpx;" src="/static/newProject/edit.png" mode=""></image>
						<text @click="jump('/pageC/grouping')">分组管理</text>
					</view>
				</view>
				<view class="top_box" @click="changeActiveName('GroupType')">
					<view class="l">
						<text>{{activeType}}</text>
						<image style="width: 7px;height: 12px;transform: rotate(90deg);"
							src="/static/newProject/equipment/icon_r.png" mode=""></image>
					</view>
					<view class="r">
						<text>类型</text>
					</view>
				</view>
				<view class="equipment_box">
					<view class="cenetr_box">
						<view class="r">
							<text>总收益：{{equipmentInfo.totalIncome}}</text>
						</view>
						<view class="r">
							<text>昨天收益：{{equipmentInfo.yesterIncome}}</text>
						</view>
					</view>
					<view class="equipment_list">
						<view v-for="(item,index) in list" :key="index" >
							<view class="equipment_item black">
								<view class="l"
									@click="jump(`/pageC/equipmentProfit?name=${item.sn}&onlineCode=${item.onlineCode}`)">
									<image :src="$fun.imgUrl(item.image)" mode=""></image>
									<view class="center_info">
										<view class="text1">
											{{item.desc ? item.desc :''}}
										</view>
										<view class="text2">
											{{item.addrIspCode}}
										</view>
										<view class="text">
											<view class="b" v-if="item.onlineCode==0">

											</view>
											<view class="b" style="background: gray;" v-else-if="item.onlineCode==1">

											</view>
											<view class="b" style="background: red;" v-else>

											</view>
											<view class="info">
												{{item.sn}}
											</view>
										</view>

									</view>
								</view>
								<view class="r">
									<view class="info">
										<text>+{{item.income}}</text>
										<text>总{{item.totalIcome}}</text>
										<text
											@click="jump(`/pageC/${item.type==0?'equipmentDetail':'equipmentDetail1'}?name=${item.sn}&onlineCode=${item.onlineCode}`)">查看详情</text>
									</view>
									<image src="/static/newProject/equipment/icon_r.png" mode=""></image>
								</view>
							</view>

						</view>
					</view>
				</view>
			</view>
			<!-- <view v-else>
				<view class="noneDate_box">
					<image src="/static/newProject/equipment_none.png" mode=""></image>
					<view class="button" @click="jump('./add')">
						去绑定 [+]
					</view>
				</view>
			</view> -->
		</scroll-view>
		<scroll-view scroll-y="true" v-else class="dial">
			<view class="equipment_list">
				<view v-for="(item,index) in list" :key="index" class="dial-item">
					<view class="equipment_item black">
						<view class="l"
							@click="jump(`/pageC/equipmentProfit?name=${item.sn}&onlineCode=${item.onlineCode}`)">
							<image :src="$fun.imgUrl(item.image)" mode=""></image>
							<view class="center_info">
								<view class="text1">
									{{item.desc ? item.desc : ''}}
								</view>
								<view class="text2">
									{{item.addrIspCode}}
								</view>
								<view class="text">
									<view class="b" v-if="item.onlineCode==0">
			
									</view>
									<view class="b" style="background: gray;" v-else-if="item.onlineCode==1">
			
									</view>
									<view class="b" style="background: red;" v-else>
			
									</view>
									<view class="info">
										{{item.sn}}
									</view>
								</view>
			
							</view>
						</view>
						<view class="r">
							<view class="info">
								<text>+{{item.income}}</text>
								<text>总{{item.totalIcome}}</text>
								<text
									@click="jump(`/pageC/${item.type==0?'equipmentDetail':'equipmentDetail1'}?name=${item.sn}&onlineCode=${item.onlineCode}`)">查看详情
								</text>
							</view>
							<image src="/static/newProject/equipment/icon_r.png" mode=""></image>
						</view>
					</view>
						<u-line></u-line>
					<view class="item-bottom">
						<navigator class="item-icon" :url="`/pageC/dialInfo/dialInfo?sn=${item.sn}`">
							<!-- <view class="item-icon" @tap=""> -->
								<view class="">
									<u-icon name="minus-circle" color="#2979ff" size="18"></u-icon>
								</view>
								<view class="item-text">
									调整线路
								</view>
							<!-- </view> -->
						</navigator>
						
						<view class="item-icon" @tap="handleDialResult(item)">
							<view class="">
								<u-icon name="question-circle" color="#2979ff" size="18"></u-icon>
							</view>
							<view class="item-text">
								拨号信息
							</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
		<view style="height: 170upx;">
		</view>
		<TabBar :tabBarShow="1"></TabBar>
		<u-modal :show="lineModal" title="提示"  showCancelButton @cancel="lineModal = false">
			<view class="">是否清退当前线路?</view>
		</u-modal>
		<u-empty mode="data"  v-if="!list.length" text="暂无设备"></u-empty>
	</view>
</template>

<script>
	import headerTop from "@/components/dacizi-headtag/dacizi-headtag.vue"
	export default {
		components: {
			headerTop
		},
		data() {
			return {
				lineModal:false,
				list1: [{
				        name: '设备',
				        }, {
				        name: '多拨号',
				        }],
				equipment: [{
						title: '全部',
						value: '-1',
						color: '#FFFFFF'
					},
					{
						title: '在线',
						value: '0',
						color: '#00FF00'
					},
					{
						title: '离线',
						value: '1',
						color: '#A0A0A0'
					},
					{
						title: '故障',
						value: '2',
						color: '#FF0000'
					},
				],
				equipmentInfo: {
					count: 0
				},
				list: [],
				page: 1,
				limit: 20,
				activeIndex: 0,
				activeName: '全部分组',
				activeType: '',
				group_id: -1,
				pipeType: '',
				GroupList: [],
				GroupType: [],
				count: 0,
				activeTab:0,
				isAdd:false,
				vlan:-1
			}
		},
		onPullDownRefresh() {
			this.page = 1
			this.list = []
				setTimeout( ()=> {
					this.getGroupList()
					uni.stopPullDownRefresh();
				}, 1000);
			},
		onReachBottom() {
			if (this.page != 1) {
				this.getUserSnList(this.page, this.limit)
			}
		},
		onNavigationBarButtonTap(e) {
			this.$fun.jump('/pageC/add')
		},
		// 分享好友
		onShareAppMessage() {
			return {
			      title: '火虎智算',
			      path: JSON.parse(uni.getStorageSync('gitH5Qrcode')), 
			    }
		},
		// 分享朋友圈
		onShareTimeline(){
			return {
			      title: '火虎智算',
			      query: JSON.parse(uni.getStorageSync('gitH5Qrcode')), 
			    }
		},
		onShow() {
			this.list = []
			this.page = 1
			this.getGroupList()
		},
		onHide() {
			this.isAdd = false
		},
		methods: {
			// 拨号信息
			handleDialResult(item){
				this.$fun.jump(`/pageC/dialResult/dialResult?sn=${item.sn}&netType=${item.netType}`)
			},
			handleScanCode(){
				let _that = this
				//#ifdef H5
				this.$fun.msg('H5暂不支持扫码！')
				//#endif
				// #ifndef H5
				uni.scanCode({
					success: function(res) {
						_that.$fun.jump(`/pageC/add?sn=${res.result}`)
					}
				});
				// #endif
			},
			handleAdd(){
				this.$fun.jump('/pageC/add')
			},
			// 拨号设置
			handleDial(){
				this.$fun.jump('/pageC/DialSetting/DialSetting')
			},
			// 点击tabs
			handleTabs(item){
				this.page = 1, 
				this.limit = 20
				if(item.index){
					this.pipeType = 3
					this.vlan = 1
				}else{
					this.pipeType = -1
					this.vlan = -1
				}
				this.list = []
				this.getUserSnList(this.page, this.limit)
				this.activeTab = item.index
			},
			changeActiveName(str) {
				let data = []
				for (var i = 0; i < this[str].length; i++) {
					data.push(this[str][i].name)
				}
				uni.showActionSheet({
					itemList: data,
					success: (res) => {
						console.log(res)
						if (str == 'GroupList') {
							this.group_id = this.GroupList[res.tapIndex].id
							this.activeName = this.GroupList[res.tapIndex].name
							this.count = this.GroupList[res.tapIndex].num
						} else {
							this.pipeType = this[str][res.tapIndex].id
							this.activeType = this[str][res.tapIndex].name
						}
						this.list = []
						this.page = 1
						this.getUserSnList(this.page, this.limit)
						// this.getGroupList()
					},
					fail: function(res) {
						console.log(res.errMsg);
					}
				});
			},
			getUserSnList(page, limit) {
				this.$fun.ajax.post('butt/userSnList', {
					page,
					limit,
					onlineCode: this.equipment[this.activeIndex].value,
					group_id: this.group_id,
					pipeType: this.pipeType,
					vlan:this.vlan
				}).then(res => {
					// console.log(res)
					if (res.data.list.length > 0) {
						this.list.push(...res.data.list);
						// this.addressList = res.data
						this.page++
					} else {
						if (this.page != 1) {
							// this.$fun.msg('没有更多数据了...')
						}
					}
					this.equipmentInfo = res.data
				})
			},
			clickItem(item, index) {
				this.activeIndex = index
				this.list = []
				this.page = 1
				this.getUserSnList(this.page, this.limit)
			},
			async getGroupList(onlineCode = -1) {
				await this.$fun.ajax.post('butt/groupList', {
					onlineCode,
				}).then(res => {
					this.GroupList = res.data
					this.count = res.data[0].num
					this.activeName = res.data[0].name
				})
				await this.$fun.ajax.post('butt/typeList', {
					onlineCode,
				}).then(res => {
					this.GroupType = res.data
					this.activeType = res.data[0].name
					this.pipeType = res.data[0].id
				})
				// await this.$fun.ajax.post('butt/typeList', {
				// 	onlineCode,
				// }).then(res => {
				// 	this.GroupType = res.data
				// 	this.activeType = res.data[0].name
				// 	this.pipeType = res.data[0].id
				// })
				await this.getUserSnList(this.page, this.limit)
			},
			jump(url) {
				this.$fun.jump(url)
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #EEEEEE;
	}

	.equipment {
		.equipment-navbar{
			.equipment-add{
				position: relative;
				/* #ifdef MP-WEIXIN */
				height: 100rpx;
				/* #endif */
				/* #ifndef MP-WEIXIN */
				height: 150rpx;
				/* #endif */
				background-color: #2a80f7;
				display: flex;
				justify-content: space-between;
				align-items: flex-end;
				padding-bottom: 15rpx;
				padding-right: 20rpx;
				.right{
					font-size: 14px;
					color: #fff;
				}
			}
		}
		.equipment-main{
			position: relative;
			.mask{
				background-color: transparent;
				position: absolute;
				z-index: 99;
				top: 0;
				left: 0;
				width: 100%;
				height: 1000rpx;
				
				.position-add{
					position: absolute;
					top: 0;
					right: 20rpx;
					background-color: #f9f9f9;
					width: 180rpx;
					color: #000;
					border-radius: 10rpx;
					padding: 5rpx;
					.item-add{
						padding: 20rpx 0;
						font-size: 14px;
						font-weight: 600;
						text-align: center;
					}
				}
			}
		}
		.top_equipment {
			padding-top: 20rpx;
			width: 100%;
			height: 88rpx;
			background: #2a80f7;
			box-sizing: border-box;
			padding: 0 0rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.top_item {
				width: 25%;
				height: 88rpx;
				position: relative;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				font-family: Microsoft YaHei;
				color: #fff;
				font-size: 30rpx;
				// border: 1rpx solid #2b7cff;
				// border-radius: 10rpx;

				.num {
					margin-bottom: 20rpx;
					font-weight: bold;
				}

				.circular {
					position: absolute;
					top: 15rpx;
					right: 15rpx;
					width: 15rpx;
					height: 15rpx;
					border-radius: 50%;
				}
			}

			.active {
				// border-radius: 10rpx;
				background: #fff;
				color: #ffa136;
			}
		}

		.top_box {
			background: #FFFFFF;
			display: flex;
			padding: 0 32rpx;
			height: 95rpx;
			align-items: center;
			justify-content: space-between;

			.l {
				display: flex;
				align-items: center;

				image {
					margin-left: 13rpx;
					margin-right: 10rpx;
					width: 33rpx;
					height: 38rpx;
				}

				text {
					font-size: 32rpx;
					font-family: Source Han Sans CN;
					font-weight: 500;
					color: #333333;
				}
			}

			.r {
				display: flex;
				align-items: center;
				font-size: 24rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #2a80f7;

				image {
					margin-right: 10rpx;
				}
			}
		}

		.equipment_box {
			padding: 0rpx 30rpx;


			.cenetr_box {
				margin-top: 29rpx;
				height: 80rpx;
				background: #EEEEEE;
				border-radius: 10px;
				display: flex;
				justify-content: space-between;
				align-items: center;
				// padding: 0 30rpx;
				box-sizing: border-box;

				.l {
					font-size: 20rpx;
					font-family: Microsoft YaHei;
					font-weight: bold;
					color: #333333;
				}

				.r {
					width: 336rpx;
					height: 80rpx;
					background: #2a80f7;
					border-radius: 10rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					font-size: 26rpx;
					font-family: Source Han Sans CN;
					font-weight: 500;
					color: #FFFFFF;

					image {
						margin-left: 90rpx;
						width: 24rpx;
						height: 14rpx;
					}
				}
			}

			
		}
		.equipment_list {
			margin-top: 20rpx;
			
			.equipment_item {
				margin-bottom: 20rpx;
				width: 100%;
				padding: 25rpx 30rpx;
				border-radius: 10rpx;
				box-sizing: border-box;
				display: flex;
				justify-content: space-between;
				background-color: #fff;
		
				.l {
					display: flex;
		
					image {
						width: 165rpx;
						height: 165rpx;
						border-radius: 10rpx;
					}
		
					.center_info {
						margin-left: 14rpx;
						display: flex;
						flex-direction: column;
						width: 300rpx;
		
						.text1 {
							font-size: 32rpx;
							font-family: Source Han Sans CN;
							font-weight: 400;
							color: #333333;
						}
		
						.text2 {
							margin-top: 20rpx;
							font-size: 24rpx;
							font-family: Source Han Sans CN;
							font-weight: 400;
							color: #999999;
						}
		
						.text {
		
							display: flex;
							align-items: center;
		
							.b {
								width: 28rpx;
								height: 8rpx;
								background: #55B953;
								border-radius: 4rpx;
							}
		
							.info {
								width: 277rpx; //固定宽度
								overflow: hidden; //溢出隐藏
								white-space: nowrap; //不换行
								text-overflow: ellipsis; //显示...
								font-size: 24rpx;
								font-family: Source Han Sans CN;
								font-weight: 400;
								color: #999999;
							}
						}
		
					}
				}
		
				.r {
					display: flex;
					justify-content: flex-end;
					align-items: center;
		
					.info {
						height: 100%;
						display: flex;
						flex-direction: column;
						justify-content: flex-start;
						text-align: right;
		
						text:nth-child(1) {
							font-size: 24rpx;
							font-family: Microsoft YaHei;
							font-weight: 400;
							color: #FE0000;
						}
		
						text:nth-child(2) {
							margin-top: 30rpx;
							font-size: 24rpx;
							font-family: Adobe Heiti Std;
							font-weight: normal;
							color: #999999;
						}
		
						text:nth-child(3) {
							font-size: 24rpx;
							font-family: Adobe Heiti Std;
							font-weight: normal;
							color: #2a80f7;
						}
		
					}
		
					image {
						margin-left: 22rpx;
						width: 14rpx;
						height: 24rpx;
					}
				}
			}
		
			.gray {
				background: #F6F6F6;
				color: #CCCCCC;
			}
		
			.black {
				// background: #F6F6F6;
				color: #333333;
			}
		}

	}

	.noneDate_box {
		margin-top: 126rpx;
		text-align: center;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

		image {
			width: 309rpx;
			height: 317rpx;
		}

		.button {
			margin: 30rpx 0;
			width: 200rpx;
			height: 60rpx;
			background: linear-gradient(-30deg, #FE555A 0%, #F99E35 100%);
			border-radius: 30rpx;
			font-size: 22rpx;
			font-family: Microsoft YaHei;
			color: #FFFFFF;
			line-height: 60rpx;
			text-align: center;
		}
	}
	.dial{
		.equipment_list{
			padding: 20rpx 30rpx;
			.equipment_item{
				margin-bottom: 0;
				padding: 0;
				.l{
					image {
							width: 130rpx;
							height: 130rpx;
							border-radius: 10rpx;
						}
				}
			}
			.item-bottom{
				display: flex;
				justify-content: space-between;
				font-size: 12px;
				margin-top: 10rpx;
			}
			.dial-item{
				background-color: #fff;
				border-radius: 10rpx;
				padding: 10rpx;
				margin-bottom:20rpx;
				.item-icon{
					display: flex;
					align-items: center;
					.item-text{
						margin-left: 5rpx;
					}
				}
			}
		}
	}
</style>